package cn.iocoder.yudao.module.game.controller.admin.gameManufacturer;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.game.controller.admin.gameManufacturer.vo.*;
import cn.iocoder.yudao.module.game.dal.dataobject.gameManufacturer.GameManufacturerDO;
import cn.iocoder.yudao.module.game.service.gameManufacturer.GameManufacturerService;

@Tag(name = "管理后台 - 游戏厂商概况")
@RestController
@RequestMapping("/game/manufacturer")
@Validated
public class GameManufacturerController {

    @Resource
    private GameManufacturerService manufacturerService;

    @PostMapping("/create")
    @Operation(summary = "创建游戏厂商概况")
    @PreAuthorize("@ss.hasPermission('game:manufacturer:create')")
    public CommonResult<Long> createManufacturer(@Valid @RequestBody GameManufacturerSaveReqVO createReqVO) {
        return success(manufacturerService.createManufacturer(createReqVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新游戏厂商概况")
    @PreAuthorize("@ss.hasPermission('game:manufacturer:update')")
    public CommonResult<Boolean> updateManufacturer(@Valid @RequestBody GameManufacturerSaveReqVO updateReqVO) {
        manufacturerService.updateManufacturer(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除游戏厂商概况")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('game:manufacturer:delete')")
    public CommonResult<Boolean> deleteManufacturer(@RequestParam("id") Long id) {
        manufacturerService.deleteManufacturer(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得游戏厂商概况")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('game:manufacturer:query')")
    public CommonResult<GameManufacturerRespVO> getManufacturer(@RequestParam("id") Long id) {
        GameManufacturerDO manufacturer = manufacturerService.getManufacturer(id);
        return success(BeanUtils.toBean(manufacturer, GameManufacturerRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得游戏厂商概况分页")
    @PreAuthorize("@ss.hasPermission('game:manufacturer:query')")
    public CommonResult<PageResult<GameManufacturerRespVO>> getManufacturerPage(@Valid GameManufacturerPageReqVO pageReqVO) {
        PageResult<GameManufacturerDO> pageResult = manufacturerService.getManufacturerPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, GameManufacturerRespVO.class));
    }

    @GetMapping("/export-excel")
    @Operation(summary = "导出游戏厂商概况 Excel")
    @PreAuthorize("@ss.hasPermission('game:manufacturer:export')")
    @OperateLog(type = EXPORT)
    public void exportManufacturerExcel(@Valid GameManufacturerPageReqVO pageReqVO,
              HttpServletResponse response) throws IOException {
        pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
        List<GameManufacturerDO> list = manufacturerService.getManufacturerPage(pageReqVO).getList();
        // 导出 Excel
        ExcelUtils.write(response, "游戏厂商概况.xls", "数据", GameManufacturerRespVO.class,
                        BeanUtils.toBean(list, GameManufacturerRespVO.class));
    }

}